package com.yang.contorller;

import com.yang.pojo.Food;
import com.yang.pojo.FoodType;
import com.yang.service.FoodService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by 杨天可 on 2022/3/29 11:43
 */
@RestController
@RequestMapping("/api/food")
public class FoodController {
    @Resource
    FoodService foodService;

    /* 修改/新增菜品*/
    @PostMapping("/save")
    public Map<String, Object> save(@RequestBody Food food){
        return foodService.save(food);
    }

    /* 删除菜品*/
    @GetMapping("/delFood")
    public Map<String, Object> delFood(@RequestParam("foodId") Integer foodId){ return foodService.delFood(foodId); }

    /* 查找所有菜品*/
    @GetMapping("/findAll")
    public Map<String, Object> findAll(@RequestParam("userId") Integer userId,
                                       @RequestParam("foodTypeId") Integer foodTypeId,
                                       @RequestParam("name") String name,
                                       @RequestParam("currentPage") Integer currentPage,
                                       @RequestParam("pageSize") Integer pageSize){
        return foodService.findAll(userId,foodTypeId,name,currentPage,pageSize);
    }

    /* 二维码页面按类型查找菜品*/
    @GetMapping("/findByType")
    public List<Food> findByType(@RequestParam("foodTypeId") String foodTypeId, @RequestParam("userId") Integer userId){
        return foodService.findByType(foodTypeId,userId);
    }

    /* 根据id查找菜品详情*/
    @GetMapping("/findFoodById")
    public Food findFoodById(@RequestParam("foodId")Integer foodId){ return foodService.findFoodById(foodId); }

}
